﻿using System;
using System.IO;
using System.Web;

namespace Acamps.Web.controles
{
    /// <summary>
    /// Summary description for ShowImage
    /// </summary>
    public class ShowImage : IHttpHandler
    {
        //DestaqueNegocio destaqueNegocio = new DestaqueNegocio();

        public void ProcessRequest(HttpContext context)
        {
            Int32 empno;
            if (context.Request.QueryString["id"] != null)
                empno = Convert.ToInt32(context.Request.QueryString["id"]);
            else
                throw new ArgumentException("No parameter specified");

            context.Response.ContentType = "image/jpeg";
            Stream strm = ShowEmpImage(empno);
            byte[] buffer = new byte[4096];
            int byteSeq = strm.Read(buffer, 0, 4096);

            while (byteSeq > 0)
            {
                context.Response.OutputStream.Write(buffer, 0, byteSeq);
                byteSeq = strm.Read(buffer, 0, 4096);
            }       
        }

        public Stream ShowEmpImage(int empno)
        {
            //var destaque = destaqueNegocio.RecuperarDestaque(empno);

            //object img = destaque.imagem;
            //try
            //{
            //    return new MemoryStream((byte[])img);
            //}
            //catch
            //{
                return null;
            //}
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}